package kr.hkit.powerjava.chapter18;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.BoxLayout;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.GridLayout;

public class PanelDialog extends JPanel implements ActionListener {
	private JButton btnMessage01;
	private JButton btnMessage02;
	private JButton btnMessage03;
	private JButton btnMessage04;
	private JButton btnMessage05;
	private JButton btnMessage06;

	/**
	 * Create the panel.
	 */
	public PanelDialog() {

		initialize();
	}

	private void initialize() {
		setLayout(new GridLayout(0, 1, 0, 0));

		btnMessage01 = new JButton("Show Message Dialog(Warnning)");
		btnMessage01.addActionListener(this);
		add(btnMessage01);

		btnMessage02 = new JButton("Show Message Dialog(Error)");
		btnMessage02.addActionListener(this);
		add(btnMessage02);

		btnMessage03 = new JButton("Show Option Dialog(Yes No Cancel)");
		btnMessage03.addActionListener(this);
		add(btnMessage03);
		
		btnMessage04 = new JButton("Show Option Dialog(Yes No)");
		btnMessage04.addActionListener(this);
		add(btnMessage04);
		
		btnMessage06 = new JButton("Show Input Dialog(textField)");
		btnMessage06.addActionListener(this);
		add(btnMessage06);
		
		btnMessage05 = new JButton("Show Input Dialog(ComboBox)");
		btnMessage05.addActionListener(this);
		add(btnMessage05);
		
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btnMessage05) {
			actionPerformedBtnMessage05(e);
		}
		if (e.getSource() == btnMessage06) {
			actionPerformedBtnMessage06(e);
		}
		if (e.getSource() == btnMessage04) {
			actionPerformedBtnMessage04(e);
		}
		if (e.getSource() == btnMessage03) {
			actionPerformedBtnMessage03(e);
		}
		if (e.getSource() == btnMessage02) {
			actionPerformedBtnMessage02(e);
		}
		if (e.getSource() == btnMessage01) {
			actionPerformedBtnMessage(e);
		}
	}

	protected void actionPerformedBtnMessage(ActionEvent e) {
		JOptionPane.showMessageDialog(this, "범위초과", "경고",
				JOptionPane.WARNING_MESSAGE);
	}

	protected void actionPerformedBtnMessage02(ActionEvent e) {
		JOptionPane.showMessageDialog(this, "범위초과", "경고",
				JOptionPane.ERROR_MESSAGE);
	}

	protected void actionPerformedBtnMessage03(ActionEvent e) {
		String[] options = { "Well-Done", "Medium", "Rare" };
		int res = JOptionPane.showOptionDialog(this, "스테이크를 어떻게 요리 할까요?",
				"스테이크 주문", JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
		JOptionPane.showMessageDialog(null, options[res] + " 선택하셨습니다.");
	}
	protected void actionPerformedBtnMessage04(ActionEvent e) {
		String[] options = {"예", "아니오"};
		int res = JOptionPane.showOptionDialog(this, "수업 마칠까요?",
				"ㅎㅎㅎㅎ", JOptionPane.OK_CANCEL_OPTION,
				JOptionPane.PLAIN_MESSAGE, null, options, options[1]);
		JOptionPane.showMessageDialog(null, options[res] + " 쉬었다 하겠습니다"
				+ "");
	}
	protected void actionPerformedBtnMessage06(ActionEvent e) {
		String res = (String)JOptionPane.showInputDialog(this, "후식을 선택하시오",
				"후식", JOptionPane.INFORMATION_MESSAGE, null, null, "아이스크림");
		JOptionPane.showMessageDialog(this, res);
	}
	protected void actionPerformedBtnMessage05(ActionEvent e) {
		String[] selectionValues={"우유", "콜라", "커피"};
		String res = (String)JOptionPane.showInputDialog(this, "후식을 선택하시오",
				"후식", JOptionPane.INFORMATION_MESSAGE, null, selectionValues, selectionValues[0]);
		JOptionPane.showMessageDialog(this, res);
	}
}
